home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Menus / MM / PIB_Dynamic.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.1 KB  |  126 lines

  1.  
  2. function havePreviewTarget()
  3. {
  4.     var bHavePreviewTarget = false;
  5.  
  6.     if (dw.getFocus() == 'site')
  7.         bHavePreviewTarget = site.getSelection().length > 0;
  8.     else if (dw.getFocus() == 'document')
  9.         bHavePreviewTarget = dw.getDocumentDOM('document') != null;
  10.  
  11.     return bHavePreviewTarget;
  12. }
  13.  
  14. function receiveArguments()
  15. {
  16.     var whichBrowser = arguments[0];
  17.     var theBrowser = null;
  18.     var i=0;
  19.     var browserList = null;
  20.     var result = false;
  21.  
  22.     if (havePreviewTarget())
  23.     {
  24.         // Code to check if we were called from a shortcut key
  25.         if (whichBrowser == 'primary' || whichBrowser == 'secondary')
  26.         {
  27.             // get the path of the selected browser
  28.             if (whichBrowser == 'primary')
  29.             {
  30.                 theBrowser = dw.getPrimaryBrowser();
  31.             }
  32.             else if (whichBrowser == 'secondary')
  33.             {
  34.                 theBrowser = dw.getSecondaryBrowser();
  35.             }
  36.  
  37.             // match up the path with the name of the corresponding browser
  38.             // that appears in the menu
  39.             browserList = dw.getBrowserList();
  40.             while (i < browserList.length)
  41.             {
  42.                 if (browserList[i+1] == theBrowser)
  43.                     theBrowser = browserList[i];
  44.                 i+=2;
  45.             }
  46.         }
  47.         else
  48.             theBrowser = whichBrowser;
  49.  
  50.         // Only launch the browser if we have a valid browser selected
  51.         if (theBrowser != "file:///" && typeof(theBrowser) != "undefined" && theBrowser.length > 0)
  52.         {
  53.             if (dw.getFocus() == 'site')
  54.                 dw.browseDocument(site.getSelection(),theBrowser);
  55.             else
  56.                 dw.browseDocument(dw.getDocumentPath('document'),theBrowser);
  57.         }
  58.         else
  59.         {
  60.             // otherwise, if the user hit the F12 or Ctrl+F12 keys,
  61.             // ask if they want to specify a primary or secondary browser now.
  62.             if (whichBrowser == 'primary')
  63.             {
  64.                 result = window.confirm(MSG_NoPrimaryBrowserDefined);
  65.             }
  66.             else if (whichBrowser == 'secondary')
  67.             {
  68.                 result = window.confirm(MSG_NoSecondaryBrowserDefined);
  69.             }
  70.  
  71.             // If they clicked OK, show the prefs dialog with the browser panel
  72.             if (result)
  73.                 dw.showPreferencesDialog('browsers');
  74.         }
  75.     }
  76. }
  77.  
  78. function canAcceptCommand()
  79. {
  80.     var PIB = dw.getBrowserList();
  81.  
  82.     if (arguments[0] == 'primary' || arguments[0] == 'secondary')
  83.         return havePreviewTarget();
  84.  
  85.     return havePreviewTarget() && (PIB.length > 0);
  86. }
  87.  
  88. // getDynamicContent returns the contents of a dynamically generated menu.
  89. // returns an array of strings to be placed in the menu, with a unique
  90. // identifier for each item separated from the menu string by a semicolon.
  91. //
  92. // return null from this routine to indicate that you are not adding any
  93. // items to the menu
  94. function getDynamicContent(itemID)
  95. {
  96.     var browsers = null;
  97.     var PIB = null;
  98.     var i;
  99.     var j=0;
  100.     browsers = new Array();
  101.     PIB = dw.getBrowserList();
  102.     // each browser pair has the name of the browser and the path that leads
  103.     // to the application on disk. We only put the names in the menus
  104.     for (i=0; i<PIB.length; i=i+2)
  105.     {
  106.         browsers[j] = new String(PIB[i]);
  107.  
  108.         if (dw.getPrimaryBrowser() == PIB[i+1])
  109.            browsers[j] += "\tF12";
  110.         if (navigator.platform == "MacPPC")
  111.         {
  112.            if (dw.getSecondaryBrowser() == PIB[i+1])
  113.               browsers[j] += "\t \021F12";
  114.         }
  115.         else
  116.         {
  117.             if (dw.getSecondaryBrowser() == PIB[i+1])
  118.               browsers[j] += "\t Ctrl+F12";
  119.         }
  120.  
  121.         browsers[j] += ";id='"+escQuotes(PIB[i])+"'";
  122.         j = j+1;
  123.     }
  124.     return browsers;
  125. }
  126.